package com.xh.bussiness.classinteractive.service.impl;

import com.xh.bussiness.classinteractive.bean.request.ClassInteractiveStudentCommonRequest;
import com.xh.bussiness.classinteractive.model.ClassInteractiveStudentCommon;
import com.xh.bussiness.classinteractive.dao.ClassInteractiveStudentCommonMapper;
import com.xh.bussiness.classinteractive.service.IClassInteractiveStudentCommonService;
import com.xh.core.service.impl.BaseServiceImpl;
import com.xh.core.util.StringUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xh.core.bean.XhPage;
import java.util.List;
/**
 * <p>
 * 学生点评记录表 服务实现类
 * </p>
 *
 * @author Pitt Cheung
 * @since 2021-07-21
 */
@Service
public class ClassInteractiveStudentCommonServiceImpl extends BaseServiceImpl<ClassInteractiveStudentCommonMapper, ClassInteractiveStudentCommon> implements IClassInteractiveStudentCommonService {
    @Override
    public XhPage queryClassInteractiveStudentCommonPage(XhPage page, ClassInteractiveStudentCommonRequest bean) {
        QueryWrapper qw=new QueryWrapper<ClassInteractiveStudentCommon>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return (XhPage) this.dao.selectPage(page,qw);
    }

    @Override
    public List queryClassInteractiveStudentCommon(ClassInteractiveStudentCommonRequest bean) {
        QueryWrapper qw=new QueryWrapper<ClassInteractiveStudentCommon>();
        //拼装条件
        qw=prepareParams(bean, qw);

        return this.dao.selectList(qw);
    }

    @Override
    public Integer queryStudentTotalScore(String attendId) {
        return this.dao.selectSumStudentScore(attendId);
    }


    /**
     * 准备条件
     * @param bean
     * @param qw
     */
    private QueryWrapper prepareParams(ClassInteractiveStudentCommonRequest bean, QueryWrapper qw) {
        if(bean.getIds()!=null&&bean.getIds().length>0){
            qw.in("id",bean.getIds());
        }
        if (StringUtils.isNotEmpty(bean.getAttendId())) {
            qw.eq("student_attend_id", bean.getAttendId());
        }
        return qw;
    }
}
